package com.youfan.service;

import com.youfan.dao.OrderDao;
import com.youfan.model.Order;
import com.youfan.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class OrderService {
    @Autowired
    private OrderDao orderDao;

    public void insertOrder(Order order){
        Date nowdate = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
        String datestring = dateFormat.format(nowdate);
        String tradenumber = UUID.randomUUID()+datestring;
        order.setCreatetime(nowdate);
        order.setTradenumber(tradenumber);
        order.setOrderstatus(0);
        order.setPaystatus(1);
        orderDao.insertOrder(order);
    }

    public List<Order> listOrder(OrderVo orderVo){
        return orderDao.listOrder(orderVo);
    }
}
